package com.dhu.controller;

import com.alibaba.fastjson.JSONObject;
import com.dhu.dao.UserBarFollowMapper;
import com.dhu.pojo.UserBarFollow;
import com.dhu.service.UserBarFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
public class UserBarFollowController {
    @Autowired
    private UserBarFollowService userBarFollowService;

    @GetMapping("isFollowBar")
    public String isFollowBar (int userId, int barId) {
        JSONObject res = new JSONObject();
        if (userBarFollowService.ifFollowBar(userId,barId) != null) {
            res.put("code", 200);
            res.put("message", "已经关注");
            res.put("isFollowBar", true);
        } else {
            res.put("code", 200);
            res.put("message", "没有关注");
            res.put("isFollowBar", false);
        }
        return res.toJSONString();
    }

    // 改变关注
    @GetMapping("changeFollow")
    public String changeFollow (boolean isFollowBar, int userId, int barId) {
        JSONObject res = new JSONObject();
        if (userBarFollowService.changeFollow(isFollowBar, userId, barId) == 1) {
            res.put("code", 200);
            res.put("message", "更改成功");
        } else {
            res.put("code", 403);
            res.put("message", "更改失败");
        }
        return res.toJSONString();
    }
}
